import Vue from 'vue';
import App from './App';
import router from './router';
import 'lib-flexible/flexible'
import store from './store'
import {
  formatDate,
  getBeforeTime,
  toHour
} from '@/utils/filters'

import VueWechatTitle from 'vue-wechat-title'
import Toast from '@/components/common/Toast'
import Message from '@/components/common/Message'
import Loading from '@/components/common/Loading'
import AwesomePicker from 'vue-awesome-picker'
import elementImport from '@/elementImport'
import '@/mintuiImport'
import 'mint-ui/lib/style.css'
import 'element-ui/lib/theme-chalk/index.css';
import controller from '@/components/controllers/controllers'
import VueCanvasPoster from 'vue-canvas-poster'
import scroller from './vue-scroller/index'
import VueAwesomeSwiper from 'vue-awesome-swiper'
// import 'swiper/dist/css/swiper.css'
import 'swiper/swiper-bundle.css'
import { InfiniteScroll,Popup  } from 'mint-ui';
// localStorage.setItem('token', '35463953daab452e8bd1346b86eb717e')


//初始化
var _projectid = "tindex_rJFxdRfMg_project_Xs4JmP0jFd"; //项目id
var _token = "438bbab9667330460713b44564731b54"; //项目token
var _app_name = "有氧FM-微信小程序"; //应用名称
var _app_version = "1.0.0"; //应用版本
var _user_id =""
if(localStorage.getItem("userInfo")){
  _user_id = JSON.parse(localStorage.getItem("userInfo")).cardNo || JSON.parse(localStorage.getItem("userInfo")).id || ''; //用户卡号
}

sugoio.init(_token, {
    'project_id': _projectid,
    enable_hash: true,  //识别带#页面
     loaded: function (lib) {
        sugoio.register({
            "app_name": _app_name,
            "app_version": _app_version,
            "UserID": _user_id
        });
    }
});

function sugoioregister(res){
  sugoio.register({
       "app_name": _app_name,
       "app_version": _app_version,
       "UserID": _user_id
  });
}
sugoioregister()
Vue.prototype.$sugoioregister = (name) => {
  sugoioregister()
}

Vue.config.productionTip = false;
//token
Vue.prototype.$token = localStorage.token || '';
Vue.prototype.$Toast = Toast;
Vue.prototype.$message = Message;

Vue.use(VueWechatTitle)
Vue.use(Loading)
Vue.use(AwesomePicker);
Vue.use(VueCanvasPoster)
Vue.use(scroller)
Vue.use(VueAwesomeSwiper, /* { default global options } */ )
Vue.use(InfiniteScroll);
Vue.component(Popup.name, Popup);

//置入公共过滤器
Vue.filter('formatDate', formatDate);
Vue.filter('getBeforeTime', getBeforeTime);
Vue.filter('toHour', toHour);

//获取url指定的值
Vue.prototype.$GetUrlParam = (name) => { //封装方法
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
  var r = window.location.search.substr(1).match(reg); //匹配目标参数
  if (r != null) return unescape(r[2]);
  return null; //返回参数值
}

Vue.prototype.$Share = (audioId, type, title,imgurl,link) => {
  if (!localStorage.getItem('token')) {
    router.push("/login")
  } else {
    router.push({
      name: "AudioSharing",
      query:{
        audioId:audioId,
        type:type,
        title:title,
        imgurl:imgurl,
        link:link
      }
    })
  }
},

Vue.prototype.$updateScore=(source,rid)=>{
  console.log(source)
  let data={source}
  if(rid){
    data.rid=rid
  }
  controller.updateScore(data).then(res => {

  })
}

Vue.prototype.$toLogin = () =>{
  router.push("/login")
}
Vue.prototype.$updateScore(1)
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})
